package router

import (
	"apifast/middleware"

	"github.com/gin-gonic/gin"
)

type HandleFunc func(*gin.RouterGroup)

var (
	_routers  = make(map[string]HandleFunc)
	_jrouters = make(map[string]HandleFunc)
)

func Register(root string, handle HandleFunc) {
	_routers[root] = handle
}

func RegisterJWT(root string, handle HandleFunc) {
	_jrouters[root] = handle
}

func Init(r *gin.RouterGroup) {
	for k, v := range _routers {
		v(r.Group(k))
	}
	for k, v := range _jrouters {
		v(middleware.UseJWTAuth(r.Group(k)))
	}
}
